home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / misc / libx11.lha / libX11 / resource_list.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-22  |  2.9 KB  |  122 lines

  1. /* Copyright (c) 1996 by Terje Pedersen.  All Rights Reserved   */
  2. /*                                                              */
  3. /* By using this code you will agree to these terms:            */
  4. /*                                                              */
  5. /* 1. You may not use this code for profit in any way or form   */
  6. /*    unless an agreement with the author has been reached.     */
  7. /*                                                              */
  8. /* 2. The author is not responsible for any damages caused by   */
  9. /*    the use of this code.                                     */
  10. /*                                                              */
  11. /* 3. All modifications are to be released to the public.       */
  12. /*                                                              */
  13. /* Thats it! Have fun!                                          */
  14. /* TP                                                           */
  15. /*                                                              */
  16.  
  17. /***
  18.    NAME
  19.      resource_list
  20.    PURPOSE
  21.      
  22.    NOTES
  23.      
  24.    HISTORY
  25.      Terje Pedersen - Mar 14, 1995: Created.
  26. ***/
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31.  
  32. #include "resource_list.h"
  33. #include "libx11.h"
  34. #include "amigax_proto.h"
  35.  
  36. listnode *makenode(char *name,char *data){
  37.   listnode *n=malloc(sizeof(listnode));
  38.   char *str1=NULL,*str2=NULL;
  39.   if(!n) X11resource_exit(RESOURCE1);
  40.   if(name!=NULL){
  41.     str1=malloc(strlen(name)+1);
  42.     if(!str1) X11resource_exit(RESOURCE2);
  43.     strcpy(str1,name);
  44.   }
  45.   if(data!=NULL){
  46.     str2=malloc(strlen(data)+1);
  47.     if(!str2) X11resource_exit(RESOURCE3);
  48.     strcpy(str2,data);
  49.   }
  50.   n->name=str1;
  51.   n->data=str2;
  52.   n->next=NULL;
  53.   return(n);
  54. }
  55.  
  56. void makenull(listnode **list){
  57.   listnode *n=malloc(sizeof(listnode));
  58.   if(!n) X11resource_exit(RESOURCE4);
  59.   n->data=(char*)999;
  60.   n->name=(char*)999;
  61.   n->next=NULL;
  62.   *list=n;
  63. }
  64.  
  65. void insert(listnode **list,listnode *n){
  66.   listnode *p=*list,*prev=*list;
  67.   if((int)p->data==999||stricmp(n->name,p->name)<0){
  68.     n->next=*list;
  69.     *list=n;
  70.     return;
  71.   }
  72.   while((int)p->data!=999&&stricmp(p->name,n->name)<=0){
  73.     prev=p;
  74.     p=p->next;
  75.   }
  76.   n->next=p;
  77.   prev->next=n;
  78. }
  79.  
  80. char *findentry(listnode *list,char *name){
  81.   listnode *p=list;
  82.   while((int)p->data!=999&&stricmp(name,p->name)!=0) p=p->next;
  83.   if((int)p->data!=999) return p->data;
  84.   return NULL;
  85. }
  86.  
  87. void deleteentry(listnode **list,char *name){
  88.   listnode *p=*list,*prev=*list;
  89.   if((int)p->data==999) return;
  90.   if(stricmp(name,p->name)==0){
  91.     *list=(*list)->next;
  92.     free(p->name);
  93.     free(p->data);
  94.     free(p);
  95.     return;
  96.   }
  97.   while((int)p->data!=999&&stricmp(p->name,name)!=0){
  98.     prev=p;
  99.     p=p->next;
  100.   }
  101.   if((int)p->data!=999){
  102.     prev->next=p->next;
  103.     free(p->name);
  104.     free(p->data);
  105.     free(p);
  106.   }
  107. }
  108.  
  109. void deletelist(listnode **list){
  110.   listnode *p;
  111.   while(*list!=NULL){
  112.     p=*list;
  113.     *list=(*list)->next;
  114.     if((int)p->data!=999){
  115.       free(p->name);
  116.       free(p->data);
  117.     }
  118.     free(p);
  119.   }
  120. }
  121.  
  122.